Online-Academy
Look, Read, Understand, Apply

Q and A 2025

What kind of language is JAVA?

Anwer: It is object-oriented programming language. It is compiled and interpreted language.

How is Java program executed?

Answer: Java program is first compilied with compiler javac and then the compilied code (class file or bytecode) is executed (interpreted) by interpreter java.

why is Java program called portable?

Answer: It is called portable because, bytecode (compiled java program) can run in any platform (OS) as Java Virtual Machine (JVM) is available for all the platforms (OSs).

From where java program starts?

Answer: From main function (method) java program starts execution.

What is a class?

Answer: Class is bundle (aggregation) of attributes (state) and methods (behavior).

Write a program to show constructor overloading.

class box{
    //private member variables
    private int weight;
    private int breadth;
    private int height;
    //public constructors and member functions 
    //constructor overloading
    public box(){//constructor without parameter
        weight = 2; 
        breadth = 3;
        height =4;
    }
    public box(int a){//constructor with single parameter
        weight = breadth = height =a;
    }
    public box(int h,int b, int w){//constructor with more than one parameter
        weight = w;
        height = h;
        breadth = b; 
    }
    public int getBreadth(){
        return breadth; 
    }
    public int getWeight(){
        return weight; 
    }
    public int getHeigth(){
        return height; 
    }
}

class box_driver{
    public static void main(String[] args){
        box b = new box();
        box b1 = new box(2,3,4);
        box b2 = new box(44,43,45);
        System.out.println("Breadth: "+b.getBreadth()+" Height: "+b.getHeigth());
        System.out.println("Breadth: "+b1.getBreadth()+" Height: "+b1.getHeigth());
        System.out.println("Breadth: "+b2.getBreadth()+" Height: "+b2.getHeigth());
    }
}